#ifndef XLCOMM_NET_EPOLLPOLLER_H_
#define XLCOMM_NET_EPOLLPOLLER_H_

#include <sys/epoll.h>

#include <vector>

#include "xlcomm/net/poller/poller.h"

namespace xlcomm {
namespace net {

// IO多路复用 epoll子类实现
class EPollPoller : public Poller {
 public:
  EPollPoller(EventLoop* loop);
  ~EPollPoller() override;

  Timestamp Poll(int timeout_ms, ChannelList* active_channels) override;

  void UpdateChannel(Channel* channel) override;

  void RemoveChannel(Channel* channel) override;

 private:
  using EventList = std::vector<epoll_event>;

  static const int kInitEventListSize = 16;

  // 填充活动的Channels
  void FillActiveChannels(int readyn, ChannelList* active_channels) const;
  // 更新监听事件
  void EpollCtl(int operation, Channel* channel);
  // 操作类型转字符串
  const char* OperationToString(int op);

  int epoll_fd_;
  EventList event_list_;
};

}  // namespace net
}  // namespace xlcomm

#endif  // XLCOMM_NET_POLLER_H_